<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        for (var i = 0; i <= 5; i++) {
            (function (j) {
                setTimeout(function () {
                    console.log(j);
                }, j * 1000)
            })(i) // 我们把i传递进去，给到j，每次循环，传递的i都是各自的。然后IIFE每次封闭的作用域里面的形参也是各自的，这样定时器就能够访问到了
        }
    </script>
</body>

</html>